package kr.co.doriclassic.chapter24;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;


public class CopyFileStream {
	
	public static void main(String[] args) {
		BufferedOutputStream fos=null;
		BufferedInputStream fis=null;
	
		long start, end;
		try {
			//이미지도 읽을 수 있다.
			fis = new BufferedInputStream(new FileInputStream("Chrysanthemum.jpg"));
			fos = new BufferedOutputStream(new FileOutputStream("수국화.jpg", false));
			start = System.currentTimeMillis();
			int c;
			while((c=fis.read())!=-1){
				//System.out.printf("%s",(char)c);
				fos.write(c);
			}
			end = System.currentTimeMillis();
			System.out.println("걸린시간" + (end-start));
		} catch (FileNotFoundException e) {
			System.out.format("%s%n","파일이 존재하지 않음");
		} catch (IOException e) {} finally{
			if(fis!=null){
				try {fis.close();} catch (IOException e) {}
			}
			if(fos!=null){
				try {fos.close();} catch (IOException e) {}
			}
		}		
	}
}
